package com.eascs.web.o2o.scheduler.history;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.StopWatch;
import com.eascs.web.o2o.dc.dao.WorkFlowDao;
import com.eascs.web.o2o.scheduler.dao.BaseDao;
import com.eascs.web.o2o.scheduler.dao.ServiceDao;
import com.eascs.web.o2o.scheduler.entity.HrEmployee;
import com.eascs.web.o2o.scheduler.entity.HrUnit;
import com.eascs.web.o2o.scheduler.entity.O2oCustomer;
import com.eascs.web.o2o.scheduler.entity.O2oPlatformRegionalEntity;
import com.eascs.web.o2o.scheduler.entity.ProcessMonitorReport;
import com.eascs.web.o2o.scheduler.entity.PubDatadictionary;
import com.eascs.web.o2o.scheduler.entity.PubDditem;
import com.eascs.web.o2o.scheduler.service.ServiceService;
import com.eascs.workflow.common.entity.sys.PlatformRegional;
import com.eascs.workflow.common.service.sys.SysOrgService;
import com.eascs.workflow.common.vo.ModelResult;

@Service
public class AdapterDataService {

	protected final Logger logger = LoggerFactory.getLogger(getClass());

	@Inject
	BaseService baseService;
	@Inject
	ServiceDao serviceDao;
	@Inject
	BaseDao baseDao;
	@Inject
	WorkFlowDao workFlowDao;
	@Inject
	ServiceService serviceService;
	
	
	

	public void saveData() {
		savePubDatadictionary();
		savePubDditem();
		saveHrUnit();
		saveHrEmployee();
	}

	public void savePubDatadictionary() {
		baseService.loadData("SELECT * from eadb.pub_datadictionary order by ddno", PubDatadictionary.class);
	}

	public void savePubDditem() {
		baseService.loadData("SELECT * from eadb.pub_dditem order by itemno", PubDditem.class);
	}

	public void saveHrUnit() {
		baseService.loadData("SELECT * from eadb.hr_units order by unitno", HrUnit.class);
	}

	public void saveHrEmployee() {
		baseService.loadData("SELECT * from eadb.hr_employee  order by employeeno", HrEmployee.class);
	}

	public void saveCustomerAndRefundData() {
		logger.info("用户中心同步客户数据开始......");
		try {
			saveO2oCustomer();
		} catch (Exception e) {
			logger.error("用户中心同步客户数据出现异常......");
			throw e;
		}
		logger.info("用户中心同步客户数据结束......");
	}

	/**
	 * 初始化贷中数据的单号
	 * 
	 * @param sourceType
	 *            0:老系统 1:新系统 2:全量（默认）
	 * @throws Exception
	 */
	public void initLoaningBillCode(int sourceType) throws Exception {
		String condition = " 1=1 and ";
		if (sourceType == 0 || sourceType == 1) {
			condition = " source_type=" + sourceType + " and ";
		}
		// 1.初始化所有贷款编号
		String exesql = "INSERT INTO basic_information_loan_ing (loanapplyno, updatetime) SELECT loan_apply_no loanapplyno ,sysdate() updatetime FROM loan_base_info "
				+ " where " + condition
				+ " loan_apply_no not in (select loanapplyno from basic_information_loan_ing)   ORDER BY loan_apply_no";

		logger.info("贷中初始化所有贷款编号开始......");
		try {
			baseService.excute(exesql);
		} catch (Exception e) {
			logger.error("贷中初始化所有贷款编号出现异常......[{}][{}]", e, e.getMessage());
			throw e;

		}
		logger.info("贷中初始化所有贷款编号结束......");
	}

	
	/**
	 * 新系统的征信、内审、银行送审等的开始和结束时间同步到贷中
	 * 
	 * 2016年9月19日
	 */
	public void saveBasicInformationLoaning() {
		serviceService.saveLoaningData();

	}
	
	
	
	/**
	 * @Title: saveLoaning
	 * @Description: 同步贷中数据
	 * @author 张庆奇
	 * @throws Exception
	 * @return void
	 * @throws @date
	 *             2016年8月9日 下午2:55:44
	 */
	@Deprecated
	public void saveLoaning() throws Exception {
		Calendar cal = Calendar.getInstance();
		String today = new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());
		cal.add(Calendar.DATE, -1);
		String yesterday = new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());

		// 1.初始化所有贷款编号
		initLoaningBillCode(2);

		// 2.更新征信提交时间
		String sql = "SELECT wf.auditordate as credit_reporting_date,l.loanapplyno  FROM eadb.o2o_loanapply l, eadb.wf_processtask wf"
				+ " WHERE wf.auditordate >= to_date ('" + yesterday + "', 'yyyy-mm-dd') AND wf.auditordate < to_date ('"
				+ today + "', 'yyyy-mm-dd') and l.billcodecredit = wf.billcode AND l.billstatuscredit = 'RUN' "
				+ " AND wf.TASKSTATUS = 'RUN' AND l.islock = 'N' AND l.LOANAPPLYNO_MAIN IS NULL "
				+ " AND wf.islock = 'N' ORDER BY l.loanapplyno";

		String exesql = "update  basic_information_loan_ing set credit_reporting_date=? where loanapplyno=?";

		logger.info("贷中更新征信提交时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and credit_reporting_date=?");
		} catch (Exception e) {
			logger.error("贷中更新征信提交时间出现异常......");
			throw e;
		}
		logger.info("贷中更新征信提交时间结束......");

		// 3.更新征信结束时间
		sql = "SELECT credit_over_date,loanapplyno FROM ( SELECT billno AS loanapplyno, max(wf.auditordate) AS credit_over_date FROM eadb.o2o_loanapply l LEFT JOIN eadb.wf_processtaskhistory wf ON l.loanapplyno = wf.billno WHERE l.billstatuscredit = 'CLO' AND l.LOANAPPLYNO_MAIN IS NULL AND l.islock = 'N' AND billtype = 'ZX' GROUP BY billno ) t "
				+ " WHERE credit_over_date >= to_date ('" + yesterday
				+ "', 'yyyy-mm-dd') AND credit_over_date < to_date ('" + today
				+ "', 'yyyy-mm-dd') ORDER BY loanapplyno";

		exesql = "update  basic_information_loan_ing set credit_over_date=? where loanapplyno=?";

		logger.info("贷中更新征信结束时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and credit_over_date=?");
		} catch (Exception e) {
			logger.error("贷中更新征信结束时间出现异常......");
			throw e;
		}
		logger.info("贷中更新征信结束时间结束......");

		// 4. 更新内审提交时间
		sql = "SELECT wf.auditordate AS in_exam_ing_date  ,l.loanapplyno FROM eadb.o2o_loanapply l, eadb.wf_processtask wf"
				+ " WHERE  wf.auditordate >= to_date ('" + yesterday
				+ "', 'yyyy-mm-dd') AND wf.auditordate < to_date ('" + today
				+ "', 'yyyy-mm-dd') and l.billstatus = 'RUN' AND l.LOANAPPLYNO_MAIN IS NULL AND l.islock = 'N' "
				+ " AND l.billcode = wf.billcode AND wf.TASKSTATUS = 'RUN' AND wf.islock = 'N' ORDER BY l.loanapplyno";
		exesql = "update  basic_information_loan_ing set in_exam_ing_date=? where loanapplyno=?";

		logger.info("贷中更新内审提交时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and in_exam_ing_date=?");
		} catch (Exception e) {
			logger.error("贷中更新内审提交时间出现异常......");
			throw e;
		}
		logger.info("贷中更新内审提交时间结束......");

		// 5.更新内审结束时间
		sql = "SELECT in_exam_over_date,loanapplyno FROM ( SELECT billno AS loanapplyno, max(wf.auditordate) AS in_exam_over_date FROM eadb.o2o_loanapply l LEFT JOIN eadb.wf_processtaskhistory wf ON l.loanapplyno = wf.billno WHERE l.billstatus = 'CLO' AND l.LOANAPPLYNO_MAIN IS NULL AND l.islock = 'N' AND billtype = 'O2O' GROUP BY billno ) t "
				+ " WHERE in_exam_over_date >= to_date ('" + yesterday
				+ "', 'yyyy-mm-dd') AND in_exam_over_date < to_date ('" + today
				+ "', 'yyyy-mm-dd') ORDER BY loanapplyno";
		exesql = "update  basic_information_loan_ing set in_exam_over_date=? where loanapplyno=?";
		logger.info("贷中更新内审结束时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and in_exam_over_date=?");
		} catch (Exception e) {
			logger.error("贷中更新内审结束时间出现异常......");
			throw e;
		}
		logger.info("贷中更新内审结束时间结束......");

		// 6.银行送审结束时间
		sql = "SELECT re.createdate  bank_submit_over_date, re.loanapplyno FROM eadb.o2o_refund re WHERE "
				+ " re.createdate >= to_date ('" + yesterday + "', 'yyyy-mm-dd') AND re.createdate < to_date ('" + today
				+ "', 'yyyy-mm-dd')" + " AND re.islock = 'N'  ORDER BY loanapplyno";
		exesql = "update  basic_information_loan_ing set bank_submit_over_date=? where loanapplyno=?";
		logger.info("贷中更新银行送审结束时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and bank_submit_over_date=?");
		} catch (Exception e) {
			logger.error("贷中更新银行送审结束时间出现异常......");
			throw e;
		}
		logger.info("贷中更新银行送审结束时间结束......");

		// 7.银行放款时间
		sql = " SELECT loaddate bank_loan_date, re.loanapplyno FROM eadb.o2o_refund re WHERE"
				+ " loaddate >= to_date ('" + yesterday + "', 'yyyy-mm-dd') AND loaddate < to_date ('" + today
				+ "', 'yyyy-mm-dd')" + " AND LOADDATE IS NOT NULL AND re.islock = 'N'  ORDER BY loanapplyno ";
		exesql = "update  basic_information_loan_ing set bank_loan_date=? where loanapplyno=?";
		logger.info("贷中更新银行放款时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and bank_loan_date=?");
		} catch (Exception e) {
			logger.error("贷中更新银行放款时间出现异常......");
			throw e;
		}
		logger.info("贷中更新银行放款时间结束......");

	}

	/**
	 * @Title: saveLoaning
	 * @Description: 同步贷中数据(全量)
	 * @author 张庆奇
	 * @throws Exception
	 * @return void
	 * @throws @date
	 *             2016年8月9日 下午2:55:44
	 */
	public void saveLoaningAll() throws Exception {
		baseService.excute("DELETE FROM basic_information_loan_ing ");
		// 1.初始化所有贷款编号
		String sql = "";// 查询
		String exesql = "INSERT INTO basic_information_loan_ing (loanapplyno, updatetime) SELECT loan_apply_no loanapplyno ,sysdate() updatetime FROM loan_base_info "
				+ " where loan_apply_no not in (select loanapplyno from basic_information_loan_ing)   ORDER BY loan_apply_no";

		logger.info("贷中初始化所有贷款编号开始......");
		try {
			baseService.excute(exesql);
		} catch (Exception e) {
			logger.error("贷中初始化所有贷款编号出现异常......");
			throw e;

		}
		logger.info("贷中初始化所有贷款编号结束......");
		// 2.更新征信提交时间
		sql = "SELECT wf.auditordate as credit_reporting_date,l.loanapplyno  FROM eadb.o2o_loanapply l, eadb.wf_processtask wf"
				+ " WHERE l.billcodecredit = wf.billcode AND l.billstatuscredit = 'RUN' "
				+ " AND wf.TASKSTATUS = 'RUN' AND l.islock = 'N' AND l.LOANAPPLYNO_MAIN IS NULL "
				+ " AND wf.islock = 'N' ORDER BY l.loanapplyno";
		exesql = "update  basic_information_loan_ing set credit_reporting_date=? where loanapplyno=?";

		logger.info("贷中更新征信提交时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and credit_reporting_date=?");
		} catch (Exception e) {
			logger.error("贷中更新征信提交时间出现异常......");
			throw e;
		}
		logger.info("贷中更新征信提交时间结束......");

		// 3.更新征信结束时间
		sql = "SELECT credit_over_date,loanapplyno FROM ( SELECT billno AS loanapplyno, max(wf.auditordate) AS credit_over_date FROM eadb.o2o_loanapply l LEFT JOIN eadb.wf_processtaskhistory wf ON l.loanapplyno = wf.billno WHERE l.billstatuscredit = 'CLO' AND l.LOANAPPLYNO_MAIN IS NULL AND l.islock = 'N' AND billtype = 'ZX' GROUP BY billno ) t "
				+ " ORDER BY loanapplyno";

		exesql = "update  basic_information_loan_ing set credit_over_date=? where loanapplyno=?";

		logger.info("贷中更新征信结束时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and credit_over_date=?");
		} catch (Exception e) {
			logger.error("贷中更新征信结束时间出现异常......");
			throw e;
		}
		logger.info("贷中更新征信结束时间结束......");

		// 4. 更新内审提交时间
		sql = "SELECT wf.auditordate AS in_exam_ing_date  ,l.loanapplyno FROM eadb.o2o_loanapply l, eadb.wf_processtask wf"
				+ " WHERE l.billstatus = 'RUN' AND l.LOANAPPLYNO_MAIN IS NULL AND l.islock = 'N' "
				+ " AND l.billcode = wf.billcode AND wf.TASKSTATUS = 'RUN' AND wf.islock = 'N' ORDER BY l.loanapplyno";
		exesql = "update  basic_information_loan_ing set in_exam_ing_date=? where loanapplyno=?";

		logger.info("贷中更新内审提交时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and in_exam_ing_date=?");
		} catch (Exception e) {
			logger.error("贷中更新内审提交时间出现异常......");
			throw e;
		}
		logger.info("贷中更新内审提交时间结束......");

		// 5.更新内审结束时间
		sql = "SELECT in_exam_over_date,loanapplyno FROM ( SELECT billno AS loanapplyno, max(wf.auditordate) AS in_exam_over_date FROM eadb.o2o_loanapply l LEFT JOIN eadb.wf_processtaskhistory wf ON l.loanapplyno = wf.billno WHERE l.billstatus = 'CLO' AND l.LOANAPPLYNO_MAIN IS NULL AND l.islock = 'N' AND billtype = 'O2O' GROUP BY billno ) t "
				+ " ORDER BY loanapplyno";
		exesql = "update  basic_information_loan_ing set in_exam_over_date=? where loanapplyno=?";
		logger.info("贷中更新内审结束时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and in_exam_over_date=?");
		} catch (Exception e) {
			logger.error("贷中更新内审结束时间出现异常......");
			throw e;
		}
		logger.info("贷中更新内审结束时间结束......");

		// 6.银行送审结束时间
		sql = "SELECT re.createdate  bank_submit_over_date, re.loanapplyno FROM eadb.o2o_refund re WHERE "
				+ " re.islock = 'N'  ORDER BY loanapplyno";
		exesql = "update  basic_information_loan_ing set bank_submit_over_date=? where loanapplyno=?";
		logger.info("贷中更新银行送审结束时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and bank_submit_over_date=?");
		} catch (Exception e) {
			logger.error("贷中更新银行送审结束时间出现异常......");
			throw e;
		}
		logger.info("贷中更新银行送审结束时间结束......");

		// 7.银行放款时间
		sql = " SELECT loaddate bank_loan_date, re.loanapplyno FROM eadb.o2o_refund re WHERE"
				+ " LOADDATE IS NOT NULL AND re.islock = 'N'  ORDER BY loanapplyno ";
		exesql = "update  basic_information_loan_ing set bank_loan_date=? where loanapplyno=?";
		logger.info("贷中更新银行放款时间开始......");
		try {
			baseService.loadPartPartData(sql, "", exesql,
					"select count(1) from basic_information_loan_ing where loanapplyno=? and bank_loan_date=?");
		} catch (Exception e) {
			logger.error("贷中更新银行放款时间出现异常......");
			throw e;
		}
		logger.info("贷中更新银行放款时间结束......");

	}

	/**
	 * @Title: saveRefund_add
	 * @Description:同步日增放款数据
	 * @author 张庆奇
	 * @return void
	 * @throws @date
	 *             2016年8月9日 下午3:13:29
	 */
	public void saveRefund_add() {

		// 1.插入日放款数据
		logger.info("插入放款数据开始......");
		try {
			baseService.excute("delete from report_refund_add");
			baseService.excute(
					"INSERT INTO report_refund_add ( bill_code, loan_type,is_renew_loan,province, loan_name, id_num, operator_name, ltd, ltd_name, loan_date, loan_amount, loan_bank, loanrate, rec_deposite_rate, rec_manger_rate, rec_risk_rate, rec_deposite, rec_manger, rec_risk, source_type, oper_time ) SELECT * FROM ( SELECT base.bill_code, loan_type, is_renew_loan, ( SELECT o.regional_name FROM ( SELECT o.regional_name, o.province_code FROM o2o_platform_regional o GROUP BY o.province_code ) o WHERE base.operator_province = o.province_code ) AS province, CONCAT( base.crmotoloanersur, base.crmotoloaner ) AS loan_name, base.idcard AS id_num, base.operator_name, base.operator_agency AS ltd, ( SELECT CONCAT(s.unitcode, '-', s.namecn) FROM hr_units s WHERE s.unitno = base.operator_agency ) AS ltd_name, base.loan_time AS loan_date, base.bank_loan_amount, ( SELECT d.itemname FROM PUB_DDITEM d WHERE d.DDNO = 10340 AND d.itemcode = base.bankrefund ) AS loan_bank, base.loanrate, base.deposite_rate, base.manger_rate, base.risk_rate, base.rec_deposite, base.rec_manger, base.rec_risk, base.source_type, now() AS oper_time FROM loan_base_info base WHERE base.loan_time IS NOT NULL ) t");
			logger.info("插入放款数据结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：插入放款数据失败！！！");
		}

		// 2.更新贷款次数
		String exesql = "update report_refund_add a  set a.loan_num =(select loan_num from o2o_customer  c  where a.id_num=c.idcard)  ";

		logger.info("同步放款数据更新贷款次数开始......");
		try {
			baseService.excute(exesql);
		} catch (Exception e) {
			logger.error("同步放款数据更新贷款次数出现异常......");
			throw e;
		}

		logger.info("同步新系统的日增放款数据更新贷款次数时间结束......");

	}

	/**
	 * @Title: saveO2oCustomer
	 * @Description: 数据中心增加客户数据
	 * @author 张庆奇
	 * @return void
	 * @date 2016年8月8日 下午3:04:14
	 */
	public void saveO2oCustomer() {

		// 1.插入新老系统的客户数据
		String sql = "select customer_id,customer_code,customer_name,id_type as idcard_type ,id_number as idcard ,mate_id,now() as oper_time from customer_basic_info where customer_source=1 and to_days( now( ) ) - to_days( modify_date) = 1  ";
		logger.info("同步crm客户信息到客户中心开始......");
		try {
			baseService.loadCrmCustomerBaseData(sql);
			logger.info("同步crm客户信息到数据中心结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：同步crm客户信息到数据中心信息失败！！！");
		}

		// 2.更新贷款次数
		sql = "select customer_id, idcard_type,idcard from o2o_customer ";
		String exsql = "update o2o_customer set loan_num=? where customer_id=?  ";
		logger.info("更新数据中心客户信息贷款次数开始......");
		try {
			baseService.updateCustomerLoanNum(sql, exsql);
			logger.info("更新数据中心客户信息贷款次数结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：更新数据中心客户信息贷款次数失败！！！");
		}

		// 3.更新第一次放款时间
		sql = "select customer_id, idcard_type,idcard from o2o_customer ";
		exsql = "update o2o_customer set first_loan_time=? where customer_id=?  ";
		logger.info("更新数据中心客户信息第一次放款时间开始......");
		try {
			baseService.updateCustomerFirstLoanTime(sql, exsql);
			logger.info("更新数据中心客户信息第一次放款时间结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：更新数据中心客户信息第一次放款时间失败！！！");
		}

	}

	public void saveAllO2oCustomer() {

		// 1.插入新老系统的客户数据
		String sql = "select customer_id,customer_code,customer_name,id_type as idcard_type ,id_number as idcard ,mate_id,now() as oper_time from customer_basic_info";
		logger.info("同步crm客户信息到客户中心开始......");
		try {
			baseService.loadCrmData(sql, O2oCustomer.class, "delete from o2o_customer");
			logger.info("同步crm客户信息到数据中心结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：同步crm客户信息到数据中心信息失败！！！");
		}

		// 2.更新贷款次数
		sql = "select customer_id, idcard_type,idcard from o2o_customer ";
		String exsql = "update o2o_customer set loan_num=? where customer_id=?  ";
		logger.info("更新数据中心客户信息贷款次数开始......");
		try {
			baseService.updateCustomerLoanNum(sql, exsql);
			logger.info("更新数据中心客户信息贷款次数结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：更新数据中心客户信息贷款次数失败！！！");
		}

		// 3.更新第一次放款时间
		sql = "select customer_id, idcard_type,idcard from o2o_customer ";
		exsql = "update o2o_customer set first_loan_time=? where customer_id=?  ";
		logger.info("更新数据中心客户信息第一次放款时间开始......");
		try {
			baseService.updateCustomerFirstLoanTime(sql, exsql);
			logger.info("更新数据中心客户信息第一次放款时间结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：更新数据中心客户信息第一次放款时间失败！！！");
		}

	}

	/**
	 * 更新贷款时间和贷款状态
	 * 
	 * 2016年8月16日
	 */
	public void updateFKDate() {
		logger.info("更新贷款时间和贷款状态开始......");
		try {
			baseService.updateFKDate();
			logger.info("更新贷款时间和贷款状态结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：更新贷款时间和贷款状态失败！！！");
			throw e;
		}
	}

	
	// 更新放款时间
	public void updateLoantime() {
		logger.info("更新放款时间数据同步开始......");
		try {
			String sql = "update basic_information_loan_ing  be,loan_base_info base set  be.bank_loan_date= base.loan_time where be.loanapplyno=base.loan_apply_no ";
			baseService.excute(sql);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：更新放款时间数据同步失败！！！");
			throw e;
		}
		logger.info("更新放款时间数据同步结束......");
	}

	
	/**
	 * 废弃--改从workflow同步数据,用以下方法替换
	 * 
	 * @see #saveO2oPlatformRegional2()
	 */
	@Deprecated
	public void saveO2oPlatformRegional() {
		logger.info("用户中心平台大区数据同步开始......");
		String delSql = "delete from o2o_platform_regional";
		String sql = "insert into o2o_platform_regional(id,platform_id,platform_code,platform_name,regional_name,province_code,province_name,group_name,create_time) SELECT uuid(),hr.UNITNO ,hr.UNITCODE, hr.namecn,"
				+ " CASE WHEN (item.itemname = '海南') THEN '广东' WHEN (item.itemname = '四川') THEN '川渝' WHEN (item.itemname = '重庆') THEN '川渝' ELSE item.itemname END, "
				+ " hr.province, item.itemname,"
				+ " CASE WHEN (item.itemname = '广东') THEN 'A'   WHEN (item.itemname = '海南') THEN 'A'  WHEN (item.itemname = '湖南') THEN 'A' WHEN (item.itemname = '山东') THEN 'A' "
				+ " WHEN (item.itemname = '广西') THEN 'A' WHEN (item.itemname = '河南') THEN 'A' WHEN (item.itemname = '福建') THEN 'A'  "
				+ " WHEN (item.itemname = '浙江') THEN 'A' WHEN (item.itemname = '安徽') THEN 'A' WHEN (item.itemname = '贵州') THEN 'B'  "
				+ " WHEN (item.itemname = '重庆') THEN 'B' WHEN (item.itemname = '四川') THEN 'B' WHEN (item.itemname = '北京') THEN 'B'  "
				+ " WHEN (item.itemname = '江苏') THEN 'B' WHEN (item.itemname = '河北') THEN 'B' WHEN (item.itemname = '江西') THEN 'B'  "
				+ " WHEN (item.itemname = '云南') THEN 'B' WHEN (item.itemname = '山西') THEN 'B' WHEN (item.itemname = '湖北') THEN 'B'  "
				+ " ELSE 'O' END, "
				+ " SYSDATE() FROM hr_units hr LEFT JOIN pub_dditem item ON hr.province = item.itemcode WHERE item.ddno = 159 ";
		try {
			baseService.excute(delSql);
			baseService.excute(sql);
			logger.info("用户中心平台大区数据同步结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：用户中心平台大区数据同步失败！！！");
			throw e;
		}

		logger.info("service系统平台大区数据同步开始......");
		sql = "select * from o2o_platform_regional";
		try {
			baseService.loadBaseDataToService(sql, O2oPlatformRegionalEntity.class, delSql);
			logger.info("service系统平台大区数据同步结束......");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("Error：service系统平台大区数据同步失败！！！");
			throw e;
		}
	}

}
